// pages/file.js
Page({
  data: {

  },
  saveFile() {
    wx.downloadFile({
      url: 'https://tse3-mm.cn.bing.net/th/id/OIP-C.acXMsW8tffHPF_lhTveweQAAAA?w=213&h=213&c=7&r=0&o=5&pid=1.7',
      success(res) {
        var path = res.tempFilePath
        console.log('临时路径=' + path)
        wx.saveFile({
          tempFilePath: path,
          success(res) {
            var savedFilePath = res.savedFilePath
            console.log('本地文件路径' + savedFilePath);
          }
        })
      }
    })
  },
  getSaveFileList(e) {
    wx.getSavedFileList({
      success(res) {
        var FileList = res.fileList
        console.log(FileList);
        for (var i = 0; i < FileList.length; i++) {
          var file = FileList[i]
          console.log('第' + (i + 1) + '个文件');
          console.log('文件的创建时间=' + file.createTime);
          console.log('文件大小=' + file.size);
          console.log('文件本地路径=' + file.filePath);
        }
      }
    })
  },
  getSaveFileInfo() {
    wx.getSavedFileList({
      success(res) {
        var fileList = res.fileList
        wx.getSavedFileInfo({
          filePath: fileList[1].filePath,
          success(res) {
            console.log("文件大小" + res.size + ",创建于" + res.createTime);
          }
        })
      }
    })
  },
  removeSaveFile() {
    wx.getSavedFileList({
      success(res) {
        var fileList = res.fileList
        console.log(fileList)
        var file = fileList[1]
        wx.removeSavedFile({
          filePath: file.filePath,
          complete(res) {
            console.log(res);
          }
        })
      }
    })
  },
  openDocument() {
    wx.downloadFile({
      url: 'https://www.baidu.com/',
      success(res) {
        var filePath = res.tempFilePath
        wx.openDocument({
          filePath,
          fileType: 'docx',
          success(res) {
            console.log('打开文档成功');
          }
        })
      },
      fail(err) {
        console.log(err);
      }
    })
  },
})